package org.codeart.driver.controller;

import org.codeart.common.util.HttpStatus;
import org.codeart.common.util.R;
import org.codeart.common.dto.Car;
import org.codeart.driver.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/car")
public class CarController {
    
    @Autowired
    private CarService carService;
    
    @PostMapping
    public R<Void> addCar(@RequestBody Car car) {
        boolean b = carService.addCar(car);
        if (b) {
            return R.ok();
        }
        return R.fail();
    }
    
    @GetMapping
    public R<Car> getCarById(@RequestParam("carId") Long carId) {
        Car car = carService.getCarById(carId);
        if (car != null) {
            return R.ok(car);
        }
        return R.fail(HttpStatus.HTTP_NOT_FOUND, "车辆信息不存在");
    }
    

}
